package com.selenium.zuoye;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class ExportXLS {
	String filePath;
	XSSFSheet sheet;
	XSSFWorkbook wb;
	
	public ExportXLS(String filePath) {
		super();
		this.filePath = filePath;
		try {
			//1、获取文件输入流
			InputStream inputStream = new FileInputStream(filePath);
			//2、获取Excel工作簿对象
			 wb = new XSSFWorkbook(inputStream);
			sheet = wb.getSheetAt(0);
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public void appendText(int rowNum,int cellNum,String text) {
		sheet.getRow(rowNum).createCell(cellNum).setCellValue(text);
	}
	
	 public void saveFile() {
		 FileOutputStream fileOut;
		try {
			fileOut = new FileOutputStream(filePath);
			wb.write(fileOut);
			wb.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
	 }
}
